package SingleDemo2;

import java.util.*;

public class Game {
    static List<Card> cards=new ArrayList<>();
    {
        String[] size = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        String[] color = {"红桃", "黑桃", "方块", "梅花"};
        int num=0;
        for(String s:size) {
            num++;
            for (String c : color) {
                cards.add(new Card(s, c,++num));
            }
        }
        cards.add(new Card("小王", "无色",++num));
        cards.add(new Card("大王", "无色",++num));
        System.out.println("一共有"+cards.size()+"张牌");
        System.out.println("洗牌前："+cards);
    }
    public static void start() {
        //洗牌
        Collections.shuffle(cards);
        System.out.println("洗牌后："+cards);
        //三个人
        Map<String,List<Card>>players=new HashMap<>();
        List<Card>l1=new ArrayList<>();
        players.put("玩家1",l1);
        List<Card>l2=new ArrayList<>();
        players.put("玩家2",l2);
        List<Card>l3=new ArrayList<>();
        players.put("玩家3",l3);

        //发牌
        for(int i=0;i<cards.size()-3;i++){
            if(i%3==0){
                Card c1=cards.get(i);
                l1.add(c1);
            }else if(i%3==1){
                Card c2=cards.get(i);
                l2.add(c2);
            }else{
                Card c3=cards.get(i);
                l3.add(c3);
            }
        }
        //对牌排序
        pokersort(l1);
        pokersort(l2);
        pokersort(l3);
        //看牌
        for(Map.Entry<String, List<Card>> entry:players.entrySet()){
            System.out.print(entry.getKey()+"的手牌:");
            List<Card> l=entry.getValue();
                System.out.print(l);

            System.out.println();
        }
    }
    public static void pokersort(List<Card> l){
        Collections.sort(l, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getNum()-o2.getNum();
            }
        });
    }
}
